package com.powerbank.common.event;

import java.io.Serializable;
import java.time.LocalDateTime;

/**
 * 基础事件类
 * 所有业务事件都应该继承此类
 */
public abstract class BaseEvent implements Serializable {
    
    private static final long serialVersionUID = 1L;
    
    /**
     * 事件ID
     */
    private String eventId;
    
    /**
     * 事件类型
     */
    private String eventType;
    
    /**
     * 事件发生时间
     */
    private LocalDateTime eventTime;
    
    /**
     * 事件来源服务
     */
    private String sourceService;
    
    /**
     * 事件版本
     */
    private String version = "1.0";
    
    public BaseEvent() {
        this.eventTime = LocalDateTime.now();
    }
    
    public BaseEvent(String eventType, String sourceService) {
        this();
        this.eventType = eventType;
        this.sourceService = sourceService;
        this.eventId = generateEventId();
    }
    
    /**
     * 生成事件ID
     */
    protected String generateEventId() {
        return eventType + "_" + System.currentTimeMillis() + "_" + 
               (int)(Math.random() * 10000);
    }
    
    // Getters and Setters
    public String getEventId() {
        return eventId;
    }
    
    public void setEventId(String eventId) {
        this.eventId = eventId;
    }
    
    public String getEventType() {
        return eventType;
    }
    
    public void setEventType(String eventType) {
        this.eventType = eventType;
    }
    
    public LocalDateTime getEventTime() {
        return eventTime;
    }
    
    public void setEventTime(LocalDateTime eventTime) {
        this.eventTime = eventTime;
    }
    
    public String getSourceService() {
        return sourceService;
    }
    
    public void setSourceService(String sourceService) {
        this.sourceService = sourceService;
    }
    
    public String getVersion() {
        return version;
    }
    
    public void setVersion(String version) {
        this.version = version;
    }
    
    @Override
    public String toString() {
        return "BaseEvent{" +
                "eventId='" + eventId + '\'' +
                ", eventType='" + eventType + '\'' +
                ", eventTime=" + eventTime +
                ", sourceService='" + sourceService + '\'' +
                ", version='" + version + '\'' +
                '}';
    }
}